<?php
//we include the needed files
include ("configs/config_log.php");

//if the user is not logged then -> redirect to login page
if ( $_SESSION['LOGIN_NAME'] <> "admin" ) {

	header("Location: login-admin.php");
	exit();
}
$tpl = new XTemplate("./template/tpl_admin.html");

if ($SUB) {

	switch ($SUB) {
		
		case "new":
			$tpl->parse("main.body.trading_traffic.add_new");
			break;
		
		case "add":
			$query = "INSERT INTO domains_stats VALUES('', '$domain', '$hits_in', '$hits_out', '$credits')";
			mysql_query($query);
			break;

		case "edit":
			$query = "UPDATE domains_stats SET domain = '$domain', hits_in = '$hits_in', hits_out = '$hits_out', 
						credits = '$credits' WHERE id = '$id'";
			mysql_query($query);
			break;
		
		case "del":
			$query = "DELETE FROM domains_stats WHERE id = '$id'";
			mysql_query($query);
			break;
			
		default:
			break;
	}
}


$tpl->parse("main.body.trading_traffic.add_new_btn");


$query = "SELECT * FROM domains_stats";
$res = mysql_query($query);

while ($row = mysql_fetch_row($res)) {
	$tpl->assign("id", $row[0]);
	$tpl->assign("domain_val", $row[1]);
	$tpl->assign("hits_in_val", $row[2]);
	$tpl->assign("hits_out_val", $row[3]);
	$tpl->assign("credits_val", $row[4]);
	$tpl->parse("main.body.trading_traffic.row");
}


$tpl->parse("main.body.trading_traffic");
$tpl->parse("main.body.menu");
$tpl->parse("main.body");

$tpl->parse("main");
$tpl->out("main");

?>
